<!DOCTYPE html>
<html>
<head>

</head>
<body>
<div id="output"></div>
<script>
    function log( msg ) {
        document.getElementById( 'output' ).innerHTML += msg + '<br>';
    }

    var limit;

    var half = '1'; //这里会换成中文再跑一遍
    var str = half;
    var sstr;

    while ( 1 ) {
        try {
            localStorage.clear();
            str += half;
            localStorage.setItem( 'cache', str );
            half = str;
        } catch ( ex ) {
            console.log(ex);
            break;
        }
    }

    var base = str.length;
    var off = base / 2;
    var isLeft = 1;

    while ( off ) {
        if ( isLeft ) {
            end = base - (off / 2);
        } else {
            end = base + (off / 2);
        }

        sstr = str.slice( 0, end );
        localStorage.clear();
        try {
            localStorage.setItem( 'cache', sstr );
            limit = sstr.length;
            isLeft = 0;
        } catch ( e ) {
            isLeft = 1;
        }

        base = end;
        off = Math.floor( off / 2 );
    }

    log( 'limit: ' + limit );

</script>
</body>
</html>